/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.gtm.base;

/**
 *
 * @author User
 */
public class ExhaustiveBestResponseFinder implements BestResponseFinder {

    private GameTheoryModel model;

    public ExhaustiveBestResponseFinder(GameTheoryModel model) {
        this.model = model;
    }

    @Override
    public ImmutableStrategy findBestResponse(int player, StrategyProfile profile) {
        ImmutableStrategy best = null;
        double bestUtility = 0;
        final PlayerValueFunction utilityFunction = model.getUtilityFunction();
        for (ImmutableStrategy s : model.getStrategiesFor(player)) {
            double utility = utilityFunction.calculate(player, s, profile);

            if (best == null || utility > bestUtility) {
                best = s;
                bestUtility = utility;
            }
        }

        return best;
    }
}
